home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
printing
/
rlpr-1.000
/
rlpr-1
/
rlpr-1.13
/
rlpr-common.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-30
|
2KB
|
78 lines
/* filename: rlpr-common.c
* project: rlpr
* author: meem -- meem@sherilyn.wustl.edu
* version: $Id: rlpr-common.c,v 1.6 1996/07/01 01:07:53 meem Exp $
* contents: general-purpose functions for rlpr
*
* Time-stamp: <1996/06/30 20:17 -- meem@sherilyn>
*/
/* copyright (c) 1996 meem, meem@gnu.ai.mit.edu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
#include <stdio.h>
#include <string.h> /* for strerror() */
#include <ctype.h>
#include <sys/stat.h> /* for fstat() */
#include <sys/utsname.h> /* for uname() */
#include <unistd.h> /* for fstat() */
#include <stdarg.h> /* for varargs */
#include "rlpr-common.h"
void rlpr_fatal(char *fmt, ...) {
va_list ap;
fprintf(stderr, "%s: fatal: ", name);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fputc('\n', stderr);
va_end(ap);
exit(1);
}
void rlpr_warn(char *fmt, ...) {
va_list ap;
if (opts_.qflag) return;
fprintf(stderr, "%s: warning: ", name);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fputc('\n', stderr);
va_end(ap);
}
void get_local_hostname(void) {
struct utsname buf;
if (uname(&buf) < 0)
rlpr_fatal("unable to resolve your local hostname!");
else {
if (strlen(buf.nodename) > MAXHOSTNAMELEN)
rlpr_fatal("your hostname is horribly long or hosed!");
else strcpy(local_hostname, buf.nodename);
}
}
void strlower(char *str) {
while ((*str++ = tolower(*str)));
}
/* this works with an fd because it is used with temporary
* files that have already been unlink()'ed.
*/
off_t filesz(int fd) {
struct stat st;
if (fstat(fd, &st) < 0)
rlpr_fatal("fd %i: %s, make sure /tmp is writable!", fd, ERRNO);
return st.st_size;
}